package com.ds.infrastructure.hyperspace.container.internal.operator;

import com.ds.infrastructure.hyperspace.common.Operator;

/**
 * usage eg:
 *  [DELIMITER_LAST_SUB_STRING, delimiter]
 * @author  Weishaoying
 */
public class DelimiterLastSubStringOperator implements Operator {

    private static final int AGRS_LENGTH = 1;

    @Override
    public String compute(String inputValue, String[] args) {
        if (inputValue == null) {
            return null;
        }
        String delimiterStr = args[0];
        int lastDelimiterStrIndex = inputValue.lastIndexOf(delimiterStr);
        if (lastDelimiterStrIndex == -1) {
            return null;
        }
        return inputValue.substring(lastDelimiterStrIndex + 1);
    }

    @Override
    public String getOperatorName() {
        return "DELIMITER_LAST_SUB_STRING";
    }

    @Override
    public int getOperatorArgsLength() {
        return AGRS_LENGTH;
    }
}
